<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>v_model的基本使用</title>
</head>
<body>
  <div id="app">
    <span>v-bind:  </span><input type="text" v-bind:value="message"><br><!--这种方式会创建单向绑定，即当 message 的值改变时，输入框的值会更新，但反向不会生效。因此，您在输入框中所做的更改不会更新 message 的值-->
    <span>v-model: </span><input type="text" v-model="message">
    <h2>{{message}}</h2>
    <h2>computed:  {{computedMessage}}</h2>
    <button>登录</button>
  </div>
  <script src="../lib/vue.js"></script>
  <script>
    // 使用vue
    const app = Vue.createApp({
      data: function(){
        return {
          message: "hello v_model"
        }
      }
      ,methods: {

      },
      computed: {
        computedMessage: {
          get() {
            return this.message
          },
          set(newValue) {
            this.message = newValue
          }
        }
      },
      watch: {
        message: {
          handler(newValue, oldValue){
            console.log("新数据: ", newValue, "旧数据: ", oldValue)
          },
          deep: true
        }
      }
    }
    )
    // 挂载 
    app.mount("#app")
  </script>

</body>
</html>
